/****************************************************************************

	COPYRIGHT(C) MAXSI SOFTWARE, JONAS 'SORTIE' TERMANSEN 2008, 2009, 2010

    This file is part of Maxsi Engine.

    Maxsi Engine is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Maxsi Engine is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Maxsi Engine. If not, see <http://www.gnu.org/licenses/>.

	*/ #include "MaxsiEngineContributors.h" /*

	If you modify this file, please enter your name below and provide contact
	information in MaxsiEngineContributors.h. For more information please see
	MaxsiEngineContributors.h.
	
	Contributors to this file:

	- Jonas 'Sortie' Termansen
	- [your name here]

	MaxsiEngine.dll
	A linkable version of Maxsi Engine

	MaxsiEngineDLL.cpp
	An interface for Dynamic Linking

****************************************************************************/

#ifndef MaxsiEngineDLL_h
#define MaxsiEngineDLL_h

#include <Windows.h>
#if 1
#define DllImport extern "C"  __declspec( dllimport )
#define DllExport extern "C"  __declspec( dllexport )
#define DllImportCPP extern __declspec( dllimport )
#define DllExportCPP extern __declspec( dllexport )
#else
#define DllImport __declspec( dllimport )
#define DllExport __declspec( dllexport )
#endif

#if 1
	#ifdef MAXSIENGINELIBRARY
		#define LINK DllExport
		#define LINKCPP DllExportCPP
		#define CLASSLINK extern "C" class __declspec( dllexport )
		#define CLASSLINKCPP extern "C++" class __declspec( dllexport )
		#define STRUCTLINK extern "C" struct __declspec( dllexport )
		#define STRUCTLINKCPP extern "C++" struct __declspec( dllexport )
	#elif defined(MAXSIENGINECUSTOMIMPLEMENTION)  // Linkers should should define this if they implement all the source code themselves
		#define LINK DllExport
		#define LINKCPP DllExportCPP
		#define CLASSLINK class
		#define CLASSLINKCPP class
		#define STRUCTLINK class
		#define STRUCTLINKCPP class
	#else
		#define LINK DllImport
		#define LINKCPP DllImportCPP
		#define CLASSLINK extern "C" class __declspec( dllimport )
		#define CLASSLINKCPP extern "C++" class __declspec( dllimport )
		#define STRUCTLINK extern "C" struct __declspec( dllimport )
		#define STRUCTLINKCPP extern "C++" struct __declspec( dllimport )
	#endif
#elif 0
	#ifdef MAXSIENGINELIBRARY // Linkers should not define this, at all, only the library itself should
		#define LINK DllExport
		#define CLASSLINK class __declspec( dllexport )
	#else
		#define LINK DllImport
		#define CLASSLINK class __declspec( dllimport )
	#endif
#else
	#ifdef MAXSIENGINELIBRARY // Linkers should not define this, at all, only the library itself should
		#define LINK DllExport
		#define CLASSLINK extern "C" class __declspec( dllexport )
	#else
		#define LINK //DllImport
		#define CLASSLINK class //extern "C" class __declspec( dllimport )
	#endif
#endif
#define DECLARE_FUNCTION(return_type, name, parameters) typedef return_type (__cdecl* type_##name  ) parameters ; \
	type_##name name
#define DECLARE_FUNCTION_HEADER(return_type, name, parameters) typedef return_type (__cdecl* type_##name  ) parameters ;
#define DECLARE_FUNCTION_SOURCE(return_type, name, parameters) type_##name name
#define DECLARE_FUNCTION_WINAPI(return_type, name, parameters) typedef return_type (WINAPI* type_##name  ) parameters ; \
	type_##name name
#define DECLARE_EXTERN_FUNCTION(return_type, name, parameters) typedef return_type (__cdecl* type_##name  ) parameters ; \
	extern type_##name name
#define IMPORT_FUNCTION(name) name = reinterpret_cast<type_##name>(GetProcAddress(Executable, #name ));

#ifdef _MSC_VER

namespace MaxsiEngine
{

CLASSLINK DLL
{
public:
	char* DLLPath;
	HMODULE Executable;

public:
	DLL ( void );
	~DLL ( void );

	void*			ProcAddress	(LPCSTR lpProcName );
	virtual bool	Import	( void );
	virtual bool	Import	( const char* LibraryPath );
	bool			Unload	( void );
};

};

#endif

#endif